#!/usr/bin/python

from robbus import Robbus

def main(argv = None):
	if len(argv) < 6:
		print "Usage: tailtest.py left right on off pwm"
		return
	flags = 0
	if int(argv[1]) > 0: # left indicator
		flags += 1 
	
	if int(argv[2]) > 0: # right indicator
		flags += 2	
	
	timeOn = int(argv[3])
	if timeOn >= 0 and timeOn < 8:
		flags += (timeOn << 2)
	else:
		raise ValueError("timeOn must be in [0..7]")
	
	timeOff = int(argv[4])
	if timeOff >= 0 and timeOff < 8:
		flags += (timeOff << 5)
	else:
		raise ValueError("timeOff must be in [0..7]")
	
	pwm = int(argv[5])
	if timeOff >= 0 and timeOff < 256:
		pass
	else:
		raise ValueError("pwm must be in [0..255]")

	robbus = Robbus()
	robbus.open('/dev/robbus', 9600)
	data = []
	data.append(chr(flags))
	data.append(chr(pwm))
	robbus.send('t',data)
	robbus.close()

if __name__ == "__main__":
	from sys import argv
	main(argv)
